//
//  BaseTableViewController.swift
//  SinaWeibo
//
//  Created by 胡阳 on 16/5/19.
//  Copyright © 2016年 young4ever. All rights reserved.
//

import UIKit

class BaseTableViewController: UITableViewController , VisitorViewDelegate {

    // 定义一个变量保存用户是否登录
    var userLogin: Bool = UserAccount.userLogin()
    // 定义属性保存为登陆的界面
    var visitorView: VisitorView?
    
    
    override func loadView() {
        userLogin ? super.loadView() : setupVisitorView()
    }
    
    // MARK: - 内部控制方法
    /**
     如果未登录加载未登录界面
     */
    private func setupVisitorView() {
    
        // 1.初始化未登录界面
        let loginView = VisitorView()
        loginView.delegate = self
        view = loginView
        visitorView = loginView
        
//        // 2.设置导航条item
//        let rightItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: #selector(BaseTableViewController.rightItemAction(_:)))
//        navigationItem.rightBarButtonItem = rightItem
//        let leftItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: #selector(BaseTableViewController.leftItemAction(_:)))
//        navigationItem.leftBarButtonItem = leftItem
    }
    
    func loginButtonClicked() {
        // 弹出登录界面
        let oauthVC = OAuthViewController()
        let navi = UINavigationController(rootViewController: oauthVC)
        presentViewController(navi, animated: true, completion: nil)
    }
    
    func registeButtonClicked() {
        print(UserAccount.loadAccount())
    }
    
    func leftItemAction(item: UIBarButtonItem){
        print(#function)
    }
    func rightItemAction(item: UIBarButtonItem){
        print(#function)
    }
}
